#include "Mesh/Triangle.h"

Triangle::Triangle(int off){
    offset=off;
}

void Triangle::SetVertices(Vertex *v1, Vertex *v2, Vertex *v3){
    vertex1=v1;
    vertex2=v2;
    vertex3=v3;

    InsertNewTriangleBuffer();
}
/*
void Face::ComputeNormal()
{
    /*  float4 vertexA = & m_Vertices.at(0);
        float4 vertexB = & m_Vertices.at(1);
    */
   // m_Normal = float4.Cross(vertexA, vertexB);
//}
vector<GLushort>   Triangle::Indices;

void Triangle::InsertNewTriangleBuffer(){

    if(Indices.size()==offset){
        Indices.push_back( vertex1->vertexId );
        Indices.push_back( vertex2->vertexId );
        Indices.push_back( vertex3->vertexId );
    }else{
        Indices.insert( Indices.begin()+offset,      vertex1->vertexId );
        Indices.insert( Indices.begin()+offset+1,    vertex2->vertexId );
        Indices.insert( Indices.begin()+offset+2,    vertex3->vertexId );
    }
}

void Triangle::DeleteTriangle(){
    Indices.erase(Indices.begin()+ offset, Indices.begin()+ offset+3);
}

void Triangle::UpdateTriangle(){
    Indices.at(offset)      =   vertex1->vertexId;
    Indices.at(offset+1)    =   vertex2->vertexId;
    Indices.at(offset+2)    =   vertex3->vertexId;
}

void Triangle::Print(){
    for(int i=0; i< Indices.size();i+=3){
        qDebug()<<" "<<Indices.at(i)<<" "<< Indices.at(i+1)<<" "<<Indices.at(i+2);
    }
}

GLushort * Triangle::Array(){
    return &Indices[0];
}
